package com.shinvent.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shinvent.common.Logger;
import com.shinvent.dao.BaseDao;
import com.shinvent.dao.T_STATUSDao;

public class Status extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public Status() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml");
	    PrintWriter out = response.getWriter();
	    T_STATUSDao statusDao = null;
	    
	    try{
	    	statusDao = new T_STATUSDao();
	    	statusDao.query();
	    	
	    	out.println("<?xml version=\"1.0\"?>");
	    	out.println("<STATUSES>");
	    	
	    	while(statusDao.gotoNext()){
	    		out.println("<STATUS>");
	    		out.println("<STATUS_ID>");
	    		out.println(statusDao.getString("STATUS_ID"));
	    		out.println("</STATUS_ID>");
	    		out.println("<STATUS_NAME>");
	    		out.println(statusDao.getString("STATUS"));
	    		out.println("</STATUS_NAME>");
	    		out.println("</STATUS>");
	    	}
	    	out.println("<STATUS>");
    		out.println("<STATUS_ID>");
    		out.println("</STATUS_ID>");
    		out.println("<STATUS_NAME>");
    		out.println("-");
    		out.println("</STATUS_NAME>");
    		out.println("</STATUS>");
	    	out.println("</STATUSES>");
	    	release(statusDao);
	    
	    }catch(Exception e){
	    	e.printStackTrace();
	    	Logger.logError(e);
	    }finally{
	    	release(statusDao);
	    }
	    
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	private void release(BaseDao dao){
		try{
			dao.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	

}
